import logging
import random

from google.adk.agents.invocation_context import InvocationContext
from google.adk.events.event import Event
from google.adk.agents.base_agent import BaseAgent
from typing import AsyncGenerator, override
from google.genai import types

logger = logging.getLogger(__name__)


class KebabAgent(BaseAgent):
    def __init__(self):
        super().__init__(
            name="kebab_agent",
            description="Kebab agent that responds with 'kebab' when invoked.",
        )

    @override
    async def _run_async_impl(
        self, ctx: InvocationContext
    ) -> AsyncGenerator[Event, None]:
        """Core logic to run this agent via text-based conversation.

        Args:
          ctx: InvocationContext, the invocation context for this agent.

        Yields:
          Event: the events generated by the agent.
        """
        session = ctx.session
        text = f"kebab for {session.user_id} in session {session.id} "

        logger.info(f"Generating response: {text}")

        model_response_event = Event(
            id=Event.new_id(),
            invocation_id=ctx.invocation_id,
            author=ctx.agent.name,
            branch=ctx.branch,
            content=types.ModelContent(parts=[types.Part.from_text(text=text)]),
        )
        yield model_response_event


root_agent = KebabAgent()
